






<?php
/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
//session_destroy( );
include 'controller/JO_commentOBJController.php';
if(!isset($article_id))$article_id=1;
//if(isset($_REQUEST["SO_chude"]))$article_id=$_REQUEST["SO_chude"];
$data=commentModule::getComments($article_id);
$JO["name"]=JO(array("EN"=>"Name","VI"=>"Họ Tên"));
$JO["email"]=JO(array("EN"=>"Email","VI"=>"Email"));
$JO["content"]=JO(array("EN"=>"Content here","VI"=>"Nhập nội dung nhận xét."));
$JO["capcha"]=JO(array("EN"=>"Capcha","VI"=>"Mã Xác Nhận"));
$JO["capcha"]=JO(array("EN"=>"Capcha","VI"=>"Mã Xác Nhận"));
$JO["comment"]=JO(array("EN"=>"Comment","VI"=>"Nhận Xét"));
$JO["addcomment"]=JO(array("EN"=>"Add New Comment","VI"=>"Viết Nhận Xét Mới"));
$JO["hidecommentother"]=JO(array("EN"=>"Hide Other Comments","VI"=>"Ẩn Các Nhận Xét Cũ Hơn"));
$JO["showcommentother"]=JO(array("EN"=>"Show Other Comments","VI"=>"Hiện Các Nhận Xét Cũ Hơn"));
$JO["ok"]=JO(array("EN"=>"OK","VI"=>"Nhận Xét"));
$JO["cancel"]=JO(array("EN"=>"Cancel","VI"=>"Hủy"));
$JO["entername"]=JO(array("EN"=>"Please, Enter Your Name","VI"=>"Hãy Nhập Họ Tên"));
$JO["enteremail"]=JO(array("EN"=>"Please, Enter Your Mail","VI"=>"Hãy Nhập Email"));
$JO["entercontent"]=JO(array("EN"=>"Please, Enter Content","VI"=>"Hãy Nhập Nội Dung"));
$JO["entercaptcha"]=JO(array("EN"=>"Please, Enter ImageCode","VI"=>"Hãy Nhập Mã Xác Nhận"));
$JO["commentadded"]=JO(array("EN"=>"comment success","VI"=>"Nhận xét thành công, nhận xét này sẽ được hiện thị sau khi kiểm duyệt."));
$JO["imagecodeinvalid"]=JO(array("EN"=>"Image Code Invalid","VI"=>"Mã Xác Nhận Không Chính Xác, Nếu Bạn Không Nhìn Rõ Mã Xác Nhận, Hãy Làm Mới Nó."));
$JO["commentagain"]=JO(array("EN"=>"Please, Comment again","VI"=>"Nhận Xét Chưa Được Xử Lý, Vui Lòng Nhận Xét Lại"));
$JO["emailinvalid"]=JO(array("EN"=>"Email Invalid","VI"=>"Email Không Hợp Lệ"));


$JO_language="VI";
?>
<script type="text/javascript" src="./JO_JS/vadilation.js"></script>

<div style="float: left;margin-bottom: 8px; width: 712px;">
    <div class="mar8i"></div>
    <div style="float: left; width: 704px;">
        <div style="float: left;width: 704px;height: 20px;margin-bottom: 4px;
             line-height: 20px;
             font-weight: bold;color: #C5E86A;
             position: relative;
             ">
            <?=$JO["comment"]?>(<?=count($data)?>)
            <div id="JO_show_hideaddcomment" style="position: absolute;top:0px;left: 190px;color: #C5E86A;cursor: pointer"
                  
                  >
<!--                onclick="showaddcomment();"-->
                + <?=$JO["addcomment"]?>
            </div>
        </div>
    <!--                        </div>
    <div style="float: left; width: 696px;">-->
        <div>
        <script>
            function showaddcomment(){
                
                if("<?=isset($_SESSION[ "JO_account_id" ])?$_SESSION[ "JO_account_id" ]:"null"?>"=="null"){
                    document.getElementById("txtname").value="<?=$JO["name"]?>";
                    document.getElementById("txtemail").value="<?=$JO["email"]?>";
                }else{
                    updatetime();
                }
                document.getElementById("JO_add_newcommenttxt").value="<?=$JO["content"]?>";
                document.getElementById("JO_capchari").value="<?=$JO["capcha"]?>";
                document.getElementById('siimage').src = 'captcha/create_image.php';
                document.getElementById("JO_error").innerHTML="";
                JO_display( 'JO_error',"none");
                JO_display2( 'JO_add_Commentsii');
                JO_display( 'JO_Commentsii_finish', 'none' );
            }
            function nameblur(){
                var txtname=document.getElementById("txtname");
                if(txtname.value==""){
                    txtname.value='<?=$JO["name"]?>';
                }
            }
            function namefocus(){
                var txtname=document.getElementById("txtname");
                if(txtname.value=="<?=$JO["name"]?>"){
                    txtname.value='';
                }
            }
            function capchalur(){
                var txtname=document.getElementById("JO_capchari");
                if(txtname.value==""){
                    txtname.value='<?=$JO["capcha"]?>';
                }
            }
            function capchafocus(){
                var txtname=document.getElementById("JO_capchari");
                if(txtname.value=="<?=$JO["capcha"]?>"){
                    txtname.value='';
                }
            }
            function emailblur(){
                var txtname=document.getElementById("txtemail");
                if(txtname.value==""){
                    txtname.value='<?=$JO["email"]?>';
                }
            }
            function emailfocus(){
                var txtname=document.getElementById("txtemail");
                if(txtname.value=="<?=$JO["email"]?>"){
                    txtname.value='';
                }
            }
            function contentblur(){
                var txtname=document.getElementById("JO_add_newcommenttxt");
                if(txtname.value==""){
                    txtname.value='<?=$JO["content"]?>';
                }
            }
            function contentfocus(){
                var txtname=document.getElementById("JO_add_newcommenttxt");
                if(txtname.value=="<?=$JO["content"]?>"){
                    txtname.value='';
                }
            }
            function addnewcomment(){
//                if("<?//=isset($_SESSION[ "JO_account_id" ])?$_SESSION[ "JO_account_id" ]:"null"?>"=="null"){
//                    var oname=$("#txtname");
//                    var oemail=$("#txtemail");
//                }
//                var ocontent=$("#JO_add_newcommenttxt");
//                var ocapcha=$("#JO_capchari");
                if("<?=isset($_SESSION[ "JO_account_id" ])?$_SESSION[ "JO_account_id" ]:"null"?>"=="null"){
                    if(!__FcheckFilled($("#txtname").val(),"<?=$JO["name"]?>")){
                        $("#JO_error").html("<?=$JO["entername"]?>");$('#JO_error').show(500);$("#txtname").focus();return;
                    }
                    if(!__FcheckFilled($("#txtemail").val(),"<?=$JO["email"]?>")){
                        $("#JO_error").html("<?=$JO["enteremail"]?>");$('#JO_error').show(500);
                        $("#txtemail").focus();return;
                    }
                    if(!_FcheckEmail($("#txtemail").val())){$("#JO_error").html("<?=$JO["emailinvalid"]?>");$('#JO_error').show(500);$("#txtemail").focus();return;}
                    
                }
                if(!__FcheckFilled($("#JO_add_newcommenttxt").val(),"<?=$JO["content"]?>")){$("#JO_error").html("<?=$JO["entercontent"]?>");$('#JO_error').show(500);$("#JO_add_newcommenttxt").focus();return;}
                if(!__FcheckFilled($("#JO_capchari").val(),"<?=$JO["capcha"]?>")){$("#JO_error").html("<?=$JO["entercaptcha"]?>");$('#JO_error').show(500);$("#JO_capchari").focus();return;}
                //JO_display( 'JO_add_Commentsii', 'none' );


                var url="controller/JO_ajax_navigation.php?JO_controller=JO_commentOBJController&JO_action=JO_addnewcomment";
                url+="&JO_article_key=<?=$article_id ?>";
                if("<?=isset($_SESSION[ "JO_account_id" ])?$_SESSION[ "JO_account_id" ]:"null"?>"=="null"){
                    url+="&txtname="+$("#txtname").val();
                    url+="&txtemail="+$("#txtemail").val();
                }
                var sc=$("#JO_add_newcommenttxt").val();
                while(sc.indexOf("\n")>=0){
                    sc=sc.replace("\n", "59d7d64dbcc254544f04cdb81ccff699");
                }
                url+="&JO_add_newcommenttxt="+sc;
                url+="&JO_capchari="+$("#JO_capchari").val();
                showobj_Statechange_function(url,commentreply);
            }
            function commentreply(){
                if (xmlhttp.readyState==4 && xmlhttp.status==200) {
                            var result=xmlhttp.responseText;
                            if(result=="-1"){
                                $("#JO_error").html("<?=$JO["imagecodeinvalid"]?>");
                                $('#siimage').attr("src",'captcha/create_image.php');
                                $('#JO_error').show(500);
                            }else if(result=="1"){
                                $('#JO_add_Commentsii').hide(500);
                                $('#JO_Commentsii_finish').show(500);
                                

                            }else{
                                $("#JO_error").html("<?=$JO["commentagain"]?>");
                                $('#siimage'). attr("src",'captcha/create_image.php');
                                $('#JO_error').show(500);
                            }
                        }
            }
            function display_other_comment(){
                JO_display2('JO_display_other_comment');
                
            }
        </script>
            
            <div id="JO_add_Commentsii" class="JO_add_Commentsii" style="display: none;">
                <form
                id="frmaddcomment" name="frmaddcomment" method="post"
                action="controller/JO_navigation.php"
                target="JO_integration_asynchronous"
                >
                <input type="hidden" id="JO_controller" name="JO_controller" value="JO_commentOBJController"/>
                <input type="hidden" id="JO_action" name="JO_action" value="JO_addnewcomment"/>
                <input type="hidden" id="JO_article_key" name="JO_article_key" value="1"/>
                <?
                if(isset($_SESSION[ "JO_account_id" ])){
                ?>
                <div class="JO_Comments_avatarii">
                    <div class="JO_Comments_nameii"><?=isset($_SESSION[ "JO_account_name" ])?$_SESSION[ "JO_account_name" ]:"NoName"?></div>
                    <img alt="" src="<?=isset($_SESSION[ "JO_account_avatar" ])?$_SESSION[ "JO_account_avatar" ]:"JO_images/noAvatar.gif"?>"/>
                    <div class="JO_Comments_dateii">
                        <?
                        
                        echo date('D d/m/Y')?>
                    </div>
                    <div  id="JO_timeu"  class="JO_Comments_timeii">
                        
                    </div>
                    <script>
                        function updatetime(){

                            var t=new Date() ;
                            var h=t.getHours().toString()%12;
                            var m=t.getMinutes().toString();
                            if(h<10)h="0"+h;
                            if(m<10)m="0"+m;
                            var s=t.getSeconds().toString();
                            if(s<10)s="0"+s;
                            var a=" AM";
                            if(t.getHours()>12)a=" PM";
                            $("#JO_timeu").html(h+":"+m+":"+s+a);
                            
                            setTimeout('updatetime()',1000);
                        }
                    </script>
                </div>
                <?
                }else{
                ?>
                <div class="JO_add_Comments_avatarii">
                    <span>
                        <input type="text" id="txtname" name="txtname" class="JO_add_Comments_nameii"
                               onblur="nameblur();"
                               onfocus="namefocus();"
                           value="<?=$JO["name"]?>"
                    />
                    </span>
                    <span>
                    <input type="text" class="JO_add_Comments_emailii" id="txtemail" name="txtemail"
                           onblur="emailblur();"
                           onfocus="emailfocus();"
                           value="<?=$JO["email"]?>"
                    />
                    </span>
                </div>
                <?
                }
                ?>


                <div class="mar12i"></div>
                <div class="JO_add_Comments_contentii" >
                    <img src="JO_images/comment_bubble_tip_.gif" alt=""
                         class="JO_Comments_arowii" style="border: 1px red"/>
                    <div>
                        <textarea id="JO_add_newcommenttxt" name="JO_add_newcommenttxt" cols="false"  rows="1"
                                  onblur="contentblur();"
                                  onfocus="contentfocus();"
                                  style="
                                        padding: 3px 5px 3px 6px; margin: 4px;
                                        width: 492px;
                                        border:none;
                                        color: #D9D9D9;
                                        line-height: normal;
    /*                                                        outline: none;*/
                                        height: 16px;
                                        float: left;

                                        border: 1px solid #333;
                                        background-color: #222;
                                      "><?=$JO["content"]?></textarea>
                    </div>
                    <div style="padding: 0px 4px 4px 4px;float: left;">
                        <span>
                            <input type="text" value="<?=$JO["capcha"]?>" id="JO_capchari" name="JO_capchari"
                                   onblur="capchatblur();"
                                   onfocus="capchafocus();"
                                   style="padding: 3px 5px 3px 6px;line-height: 16px;height: 16px;
                               border: 1px solid #333;
                               background-color: #222;
                            "/>
                        </span>
                        <div class="mar4i"></div>

                        <div style="width: 80px; float: left; height: 24px">
                            <img alt="" id="siimage"  align="left" style="padding-right: 4px; border: 0px;width: 48px;height: 24px;" src="captcha/create_image.php" />
                            <a tabindex="-1" style="border-style: none" href="javascript:$('#siimage').attr('src','captcha/create_image.php'); return false;" title="Refresh Image">
                                <img id="refresh_capcha" name="refresh_capcha" style="width: 24px; float: left; height: 24px"  src="php_captcha/images/refresh7.png" alt="Reload Image" border="0" onclick="this.blur()" align="bottom" />
                            </a>
                        </div>


<!--onclick="addnewcomment();"-->
                        <a href="javascript:void(0);" id="JO_addcomment" class="input_buttoni" style="height: 22px;" ><?=$JO["ok"]?></a>
                        <a href="javascript:void(0);" id="JO_cancelcomment" class="input_buttoni" style="height: 22px;" ><?=$JO["cancel"]?></a>
<!--                        onclick="JO_display( 'JO_add_Commentsii', 'none' );"-->
                    </div>
                    <div id="JO_error" style="float: left;width: 480px;line-height: 16px;padding:4px 8px;color: red">

                    </div>

                      <script type="text/javascript">

                        $('#JO_addcomment').click(
                            function () {
                                addnewcomment();
                            }
                        );
                        $('#JO_show_hideaddcomment').click(
                            function () {
                                if("<?=isset($_SESSION[ "JO_account_id" ])?"false":"true"?>"=="true"){
                                    $("#txtname").val("<?=$JO["name"]?>");
                                    $("#txtemail").val("<?=$JO["email"]?>");
                                }else{
                                    updatetime();
                                }
                                $("#JO_add_newcommenttxt").val("<?=$JO["content"]?>");
                                $("#JO_capchari").val("<?=$JO["capcha"]?>");
                                $("#siimage").attr("src",'captcha/create_image.php');
                                $("#JO_error").html("");

                                JO_display( 'JO_error',"none");
                                //JO_display2( 'JO_add_Commentsii');
                                if($('#JO_add_Commentsii').css('display') == 'block'){
                                    $('#JO_add_Commentsii').hide(500);
                                }else{
                                    $('#JO_add_Commentsii').show('slow');
                                }
                                
                                JO_display( 'JO_Commentsii_finish', 'none' );
                            }
                        );
                        $('#JO_cancelcomment').click(
                            function () {
                                $('#JO_add_Commentsii').hide(500);
                            }
                        );
                          /*<![CDATA[*///(function(a){a.fn.autoResize=function(j){var b=a.extend({onResize:function(){},animate:true,animateDuration:150,animateCallback:function(){},extraSpace:20,limit:1000},j);this.filter('textarea').each(function(){var c=a(this).css({resize:'none','overflow-y':'hidden'}),k=c.height(),f=(function(){var l=['height','width','lineHeight','textDecoration','letterSpacing'],h={};a.each(l,function(d,e){h[e]=c.css(e)});return c.clone().removeAttr('id').removeAttr('name').css({position:'absolute',top:0,left:-9999}).css(h).insertBefore(c)})(),i=null,g=function(){f.height(0).val(a(this).val()).scrollTop(10000);var d=Math.max(f.scrollTop(),k)+b.extraSpace,e=a(this).add(f);if(i===d){return}i=d;if(d>=b.limit){a(this).css('overflow-y','');return}b.onResize.call(this);b.animate&&c.css('display')==='block'?e.stop().animate({height:d},b.animateDuration,b.animateCallback):e.height(d)};c.unbind('.dynSiz').bind('keyup.dynSiz',g).bind('keydown.dynSiz',g).bind('change.dynSiz',g)});return this}})(jQuery);
                      $('textarea#JO_add_newcommenttxt').autoResize({
                        // On resize:
                        onResize : function() {
                            $(this).css({opacity:0.8});
                        },
                        // After resize:
                        animateCallback : function() {
                            $(this).css({opacity:1});
                        },
                        // Quite slow animation:
                        animateDuration : 300,
                        // More extra space:
                        extraSpace : 16
                    });
                      </script>
                </div>
                </form>
            </div>
                
        </div>
        <div id="JO_Commentsii_finish" style="display: none;">
            <?=$JO["commentadded"]?>
        </div>
    <?
        if(isset($data)){
            $num=0;
            $_no=count($data);
            foreach ($data as $commentrow){
                $num++;
                if($num==6){ echo "<div id='JO_display_other_comment' style='display:none;'>";}
                ?>
            <div class="JO_Commentsii">

                <div class="JO_Comments_avatarii">

                    <img alt="" src="<?=isset($commentrow["avatar"])?$commentrow["avatar"]:"JO_images/noAvatar.gif"?>"/>
                    <div class="JO_Comments_dateii">
                        <?
                        $_time=new DateTime($commentrow["insert"]);
                        echo $_time->format('D d/m/Y')?>
                    </div>
                    <div class="JO_Comments_timeii">
                        <?

                        echo $_time->format('h:i:s A')?>
                    </div>
                    <div class="JO_Comments_nameii"><?=isset($commentrow["name"])?("<span style='font-weight:normal'>".html_entity_decode($commentrow["name"],ENT_QUOTES,'utf-8')." (Guest)</span>"):html_entity_decode($commentrow["aname"],ENT_QUOTES,'utf-8')?></div>
                </div>
                <div class="mar12i"></div>
                <div class="JO_Comments_contentii">
                    <div style="width: 28px;height: 16px;line-height: 16px;
                         text-align: right;clear: both;float: right;margin: -4px;
                         ">#<?=$_no?></div>
                    <img src="JO_images/comment_bubble_tip_.gif" alt=""
                        class="JO_Comments_arowii"/>
                    <?=  JO_UNconvertHTMLentities($commentrow["content"])?>
                </div>
            </div>
                <?
                $_no--;
            }
            if(count($data)>5) echo "</div>";
        }
        else{
            echo "Không có nhận xét nào.";
        }
    ?>
        
    <!--                            <div style="float: left;width: 696px;height: 20px;margin-bottom: 4px;
             line-height: 20px;
             position: relative;
             ">
             <span onclick="
                  JO_display2( 'JO_add_Commentsii');
                    ">
                + Add New Comment
            </span>

        </div>-->
    <?
    if(count($data)>5){
    ?>
    <a href="javascript:void(0);" id="JO_show_hideothercomment"><?=$JO["showcommentother"]?></a>
    <script>

    $('#JO_show_hideothercomment').click(
        function (){
            if($(this).html()=="<?=$JO["showcommentother"]?>"){
                //$('#JO_display_other_comment').show(2000);
                JO_JQdisplay('#JO_display_other_comment','block');
                $(this).html("<?=$JO["hidecommentother"]?>");
            }else{
                JO_JQdisplay('#JO_display_other_comment','none');
                $(this).html("<?=$JO["showcommentother"]?>");
            }
        }
    );
    </script>
    <?
    }
    ?>
    </div>
    </div>
